<template>
  <c-back-wrap :loading="loading" go-page="市场开发/升级周进度跟进" :before-call-back="$goBackCall" current-page="编辑">
    <EditForm ref="form" :detail="detail" />
    <template slot="after">
      <!-- <c-button type="default" @click="handleCancel">取消</c-button> -->
      <c-button type="primary" @click="handleConfirm">保存</c-button>
      <c-button type="primary" @click="handleSubmit">提交</c-button>
    </template>
  </c-back-wrap>
</template>

<script>
import EditForm from './EditForm'
import { weekTaskDetail, editWeekTask, submitWeekTask } from '@/api/channelTask2/weekTask'
export default {
  name: 'Edit',
  components: {
    EditForm
  },
  props: {
    id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      detail: {}
    }
  },
  computed: {
  },
  created() {
    this.getDetailData()
  },
  methods: {
    getDetailData() {
      this.loading = true
      return weekTaskDetail(this.id).then(res => {
        this.loading = false
        this.detail = res.data
      }).catch(() => {
        this.loading = false
      })
    },
    handleCancel() {
      this.$goBackCall().then(this.$pageStack.pop)
    },
    handleConfirm() {
      return this.$refs.form.validate().then(formData => {
        const data = { ...formData }
        data.id = this.detail.id
        return editWeekTask(data).then(() => {
          this.$message.success('操作成功!')
          this.$pageStack.pop('onPage')
        })
      })
    },
    handleSubmit() {
      return this.$refs.form.validate().then(formData => {
        const data = { ...formData }
        data.id = this.detail.id
        return submitWeekTask(data).then(() => {
          this.$message.success('操作成功!')
          this.$pageStack.pop('onPage')
        })
      })
    }

  }
}
</script>
